import { defineStore } from "pinia";
import { constantRoutes } from "@/router/route";
import { GET_TOKEN } from "@/utils/token";
import { getUserInfoApi } from "@/api/UserInfo";
import { UserResponseData } from "@/api/UserInfo/res";
import { ElMessage } from "element-plus";

const useUserStore = defineStore('User', {
    state: () => {
        return {
            token: GET_TOKEN(),
            username: '',
            email: '',
            objectId: '',
            menuRoutes: constantRoutes,
        }
    },
    actions: {
        async getUserInfo() {
            try {
                const res: UserResponseData = await getUserInfoApi({ objectId: this.objectId })
                this.username = res.username
            } catch (err: any) {
                ElMessage({ type: 'error', message: err.message })
            }
        }
    }
})

export default useUserStore